import { _decorator, Component, math, Node, tween, v3 } from 'cc';
import { PropDt } from '../../../FrameWork3.8.6/FrameWork/Common/CommonInterface';
import { PropLayer } from '../ModuleLayer/PropLayer';
import { ModuleMgr } from '../../../FrameWork3.8.6/FrameWork/Module/ModuleMgr';
import { Player } from './Player';
import { GameManager } from '../Manager/GameManager';
import { PlayerLayer } from '../ModuleLayer/PlayerLayer';
import { Emitter } from '../../../FrameWork3.8.6/FrameWork/Common/Emitter';
const { ccclass, property } = _decorator;

@ccclass('Prop')
export class Prop extends Component {

    //唯一标识是自己而不是同种类型的其他道具
    private _propName:string=null;
    get(){
        return this._propName;
    }

    //当前道具自己的数据
    private _propDt:PropDt=null;

    get propDt(){
        return this._propDt;
    }

    //道具层
    private _propLayer:PropLayer=null;

    //当前玩家
    private _player:Player=null;

    //道具相隔一定时间自动消失
    private _interval:number=3;
    //当前时间
    private _time:number=0;
    onInit(propDt:PropDt,name:string){
        this._propName=name;
        //初始化道具层
        //this._propLayer=this.node.parent.getComponent(PropLayer);
        this._player=ModuleMgr.instance.getModule<PlayerLayer>("_PlayerLayer").player;
        this._propLayer=ModuleMgr.instance.getModule<PropLayer>("PropLayer");
        this._propDt=propDt;

    }

    onUpdate(dt:number){
        this._time+=dt;
        let dirX=Math.abs(this.node.worldPosition.x-this._player.node.worldPosition.x)
        if(dirX<=300){
            Emitter.instance.emit("removeProp",this._propLayer,this.node,true);
        }
        if(this._time>=this._interval){

            Emitter.instance.emit("removeProp",this._propLayer,this.node,false);
        }
    }
}


